<?php
session_start();
error_reporting(E_ERROR | E_WARNING | E_PARSE);
include 'includes/header.php';
my_header('Казина :: Jwakk');
?>

        <div class="line"></div>
        <div class="mainConteiner">

           <?php include 'includes'.DIRECTORY_SEPARATOR.'top.php'; ?>
            <div class="topDelimiter"></div>

            <div class="content">

                <table cellspacing="0" cellpadding="0" width="100%"><tr>

                        <td class="Mainmenu" valign="top">
                            <a href="index.php"><div class="manuOnB">Казина</div></a>
                            <a href="buyCasino.php"><div class="manuB">Купи казино</div></a>
                            <a href="yoursC.php"><div class="manuB">Твои казина</div></a>
                            <a href="fight.php"><div class="manuB">Сбий се</div></a>
                            <a href="work.php"><div class="manuB">Работа</div></a>
                            <a href="zalozi.php"><div class="manuB">Залози</div></a>
                            <a href="coffee.php"><div class="manuB">Градът</div></a>
                            <a href="profile.php?user=<?php echo $_SESSION['user_info']['user']; ?>"><div class="manuB">Профил</div></a>
                            <?php
								$mes_q = mysql_query('SELECT id FROM message WHERE `do`="'.$_SESSION['user_info']['user'].'" AND `read`="0"');
								$mes_n = mysql_num_rows($mes_q);
								echo '<a href="mail.php"><div class="manuB">Съобщения ['.$mes_n.']</div></a>';
							?>
                            <a href="index.php?logout"><div class="manuBLogOut">Изход</div></a>

                            <br/>
                            <a href="#"><img alt="Последвайте Jwakk в Facebook" src="img/facebook.png" /></a>
                            <a href="#"><img alt="Последвайте Jwakk в Twitter" src="img/twitter.png" /></a>
                            <a href="#"><img alt="Абонирайте се за RSS емисии" src="img/rss.png" /></a>
                        </td>

                        <td valign="top">
                            <div class="gameBorder">
                                <div class="TheGame">

                                    <form method="post" action="index.php">
                                        <input class="searchGame" type="text" name="search" value="Търси..."
                                               onblur="if(this.value=='')this.value='Търси...';" onfocus="if(this.value=='Търси...')this.value='';"/>
                                        <input class="serchSubmit" type="submit" value=""/>
                                        <input type="hidden" name="search_sub" value="1" />
                                    </form>
                                    <div class="gameTitle">Казина</div>
                                    
                                    <div id="casinoNavigate">
									<br/>
                                        <a class="tab" href="index.php">Всички казина</a>  <a class="tab" href="index.php?favourite">Любими</a>  <a class="tab" href="index.php?rich">Богати казина</a>
										<div class="del"></div>
                                    </div>
                                    <table width="100%" class="rankingTable" cellpadding="0"cellspacing="1">

                                        <tr><td class="mainrang" align="center">#</td> <td class="miancasinoNameTalbe">Име</td> <td class="mainfav">В любими</td></tr>
                                        <div class="tableCarino">
						<?php
                                                if(!empty($referal)){
                                                    echo $referal;
                                                 } 
													
                                                    if(!isset($_GET['favourite']) AND !isset($_GET['rich'])){
                                                        if($_POST['search_sub']!=1){
                                                        $i=0;
                                                        while($casino_f=mysql_fetch_assoc($casino_q))
							{
                                                            $i++;
                                                            $howfavourite_q = mysql_query('SELECT COUNT(*) as cnt FROM casino_favourite WHERE casino_id="'.$casino_f['casino_id'].'"');
                                                            $howfavourite_f = mysql_fetch_assoc($howfavourite_q);
                                                            echo '<tr><td class="rang" align="center">'.$i.'</td> <td class="casinoNameTalbe"><a href="casino.php?number='.$casino_f['casino_id'].'">'.$casino_f['name'].'</a></td> <td class="fav">'.$howfavourite_f['cnt'].'</td></tr>' ; 
							}	
                                                        }
                                                        elseif($_POST['search_sub']==1){
                                                            $search = $_POST['search'];
                                                            $search_q = mysql_query("SELECT * FROM casino WHERE name LIKE '%$search%'");
                                                            echo 'Търсене за <b>'.htmlspecialchars($search).'</b>:';
                                                            while($search_f = mysql_fetch_assoc($search_q))
                                                            {
                                                                  echo '<tr><td class="rang" align="center">'.$search_f['casino_id'].'</td> <td class="casinoNameTalbe"><a href="#">'.$search_f['name'].'</a></td> <td class="fav">2252552</td></tr>' ;   
                                                            }
                                                        }
                                                    }
                                                    elseif(isset($_GET['favourite'])){
                                                        $i=0;
                                                        $casinoFavourite_q = mysql_query('SELECT casino_id FROM casino_favourite WHERE user="'.$_SESSION['user_info']['user'].'"');
                                                        while($casinoFavourite_f = mysql_fetch_assoc($casinoFavourite_q))
                                                        {
                                                                $i++;
                                                                $casinoName_q = mysql_query('SELECT casino_id,name FROM casino WHERE casino_id="'.$casinoFavourite_f['casino_id'].'"');
                                                                $casinoName_f = mysql_fetch_assoc($casinoName_q);
                                                                $howfavourite_q = mysql_query('SELECT COUNT(*) as cnt FROM casino_favourite WHERE casino_id="'.$casinoFavourite_f['casino_id'].'"');
                                                                $howfavourite_f = mysql_fetch_assoc($howfavourite_q);
                                                                echo '<tr><td class="rang" align="center">'.$i.'</td> <td class="casinoNameTalbe"><a href="casino.php?number='.$casinoName_f['casino_id'].'">'.$casinoName_f['name'].'</a></td> <td class="fav">'.$howfavourite_f['cnt'].'</td></tr>' ; 
                                                        }
                                                    }
													elseif(isset($_GET['rich'])){
													$i=0;
														$rich_q = mysql_query('SELECT casino_id,name FROM casino ORDER BY money ASC');
														while($rich_f = mysql_fetch_assoc($rich_q)){
														$i++;
														$howfavourite_q = mysql_query('SELECT COUNT(*) as cnt FROM casino_favourite WHERE casino_id="'.$rich_f['casino_id'].'"');
														$howfavourite_f = mysql_fetch_assoc($howfavourite_q);
															echo '<tr><td class="rang" align="center">'.$i.'</td> <td class="casinoNameTalbe"><a href="casino.php?number='.$rich_f['casino_id'].'">'.$rich_f['name'].'</a></td> <td class="fav">'.$howfavourite_f['cnt'].'</td></tr>';
														}
													}
                                                    
                                                ?>
                                        </div>
                                    </table>

                                    <div class="padination">
                                        <br/>
                                        <i>Страници:</i> <a href="#">1</a> <a href="#">2</a> <span href="#">3</span> <a href="#">4</a> <a href="#">5</a> <i>....</i> <a href="#">22</a> 
                                    </div>

                                </div>
                            </div>

                            <div class="help"> <a href="#">Помощ</a> | <a href="#">FAQ</a> | <a href="#">Условия</a> | <a href="#">Facebook</a></div>
                        </td>

                    </tr></table>

               
                <?php footer(); ?>
            </div>
        </div>

        <div class="bottom"></div>

    </body>
</html>